package com.wl.index.Mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wl.entity.Comments;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface CommentMapper extends BaseMapper<Comments> {
    //通过帖子id查询评论
    @Select("SELECT * FROM comments WHERE nid = #{nid}")
    List<Comments> getCommentsByNid(Integer nid);

    //通过用户id查找用户信息
    @Select("select c.*,u.uname,u.head from comments c left join lvuser u on c.uid = u.uid where nid = #{nid}")
    List<Map<String,Object>> getCommentsByUid(Integer nid);

    //添加评论
    @Insert("INSERT INTO comments (context, creat_at, nid, uid) VALUES (#{context}, #{creatAt}, #{nid}, #{uid})")
    int addComment(Comments comments);
}
